import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import reactRefresh from '@vitejs/plugin-react-refresh'
import vitePluginImp from 'vite-plugin-imp'
import ViteAutoImport from 'unplugin-auto-import/vite'
import {visualizer} from 'rollup-plugin-visualizer'
import path from 'path'

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  return {
    plugins: [
      react(),
      reactRefresh(),
      vitePluginImp({
        libList: [
          {
            libName: "antd",
            // style: (name) => {
            //   // 过滤不需要样式文件的核心模块
            //   if (name === 'theme') return '/src/views/Add/index.tsx';
            //   return `antd/es/${name}/style/index.js`;
            // }
          },
        ],
      }),
      ViteAutoImport({
        imports: ['react', 'react-router-dom'],
        dts: './src/auto-imports.d.ts',
      }),
      visualizer({
        apply: mode === 'production' ? 'build' : false, // 仅在构建模式生效
        open: true,
        filename: './state.html',
        gzipSize: true,
        brotliSize: true
      } as any)
    ],
    css: {
      preprocessorOptions: {
        less: {
          // 支持内联 JavaScript
          javascriptEnabled: true,
        }
      }
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src')
      },
      extensions: ['.ts', '.tsx', '.js', '.jsx'],
    }
  }
})

